package com.windoent.yugioh.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.InputType;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.windoent.yugioh.R;
import com.windoent.yugioh.utils.BaseMethod;

/**
 * author : robert
 * date   : 2021/4/28 11:23
 * desc   :
 */
public class UserInfoItem extends RelativeLayout {
    private Context mConText;
    private TextView mTvTitle;
    private LinearLayout mLlEt;
    private EditText mEtContent;
    private LinearLayout mLlText;
    private TextView mTvContent;
    private boolean showtv;
    private String title;
    private String tvhint;
    private String ethint;


    public UserInfoItem(Context context) {
        this(context, null, 0);
    }

    public UserInfoItem(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public UserInfoItem(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mConText = context;
        LayoutInflater.from(mConText).inflate(R.layout.custom_view_user_info, this);
        TypedArray attributes = mConText.obtainStyledAttributes(attrs, R.styleable.UserInfoItem, 0, 0);
        try {
            showtv = attributes.getBoolean(R.styleable.UserInfoItem_showtv, false);
            title = attributes.getString(R.styleable.UserInfoItem_title);
            tvhint = attributes.getString(R.styleable.UserInfoItem_tvhint);
            ethint = attributes.getString(R.styleable.UserInfoItem_ethint);
        } finally {
            attributes.recycle();
        }
        setUpView();
    }

    private void setUpView() {
        mTvTitle = (TextView) findViewById(R.id.tv_title);
        mLlEt = (LinearLayout) findViewById(R.id.ll_et);
        mEtContent = (EditText) findViewById(R.id.et_content);
        mLlText = (LinearLayout) findViewById(R.id.ll_text);
        mTvContent = (TextView) findViewById(R.id.tv_content);

        mTvTitle.setVisibility(BaseMethod.notNull(title) ? VISIBLE : GONE);
        mTvTitle.setText(title);
        mEtContent.setHint(ethint);
        mTvContent.setHint(tvhint);
        mLlEt.setVisibility(showtv ? GONE : VISIBLE);
        mLlText.setVisibility(showtv ? VISIBLE : GONE);
    }

    public String getTvContent() {
        return mTvContent.getText().toString().trim();
    }

    public String getEtContent() {
        return mEtContent.getText().toString().trim();
    }

    public TextView getTextView() {
        return mTvContent;
    }

    public EditText getEditText() {
        return mEtContent;
    }

    public void setItemListener(OnClickListener listener) {
        mLlText.setOnClickListener(listener);
    }
}

